app.controller('sys_configViewController', ['$scope', 'httpWrapService', 'dialogs', '$state', '$stateParams',
                        '$location', '$anchorScroll', 'AlertFactory','GridFactory','validationService',
                function ($scope, httpWrapService, dialogs, $state, $stateParams, $location, $anchorScroll, AlertFactory,GridFactory,validationService) {
    $scope.entity = {};

    $scope.id = $stateParams.id;
    $scope.type = $stateParams.type || 'add';
    $scope.Alert = AlertFactory.newInstance();

    if($scope.id) {
        httpWrapService.post('system/config/view/' + $scope.id + '.do').then(function (res) {
            $scope.entity = res.data.entity;
            $scope.type = 'update';
        });
    }
    //$scope.unique = function(value){
    //    return validationService.unique({
    //        entityName : "common.rbac.po.Role",
    //        field : "role",
    //        value : value,
    //        id : $scope.id
    //    })
    //}

    $scope.save = function () {
        httpWrapService.defaultSave( 'system/config/' + $scope.type + '.do',{
            entity : $scope.entity
        }, $scope).then(function (res) {
            $state.go('app.system.config.list');
        });

        // 保存成功返回列表页面

    }
    $scope.canle = function () {
        // 后退到列表页面
        $state.go('app.system.config.list');
    }

}]);
